#-*- coding: utf-8 -*-
'''
Created on Aug 24, 2012

@author: bbg
'''

from sqlalchemy import Integer, Column, String, MetaData, Table,DateTime
from sqlalchemy.orm import mapper

class Sell_analysis(object):
    '''
    销售状况分析    
    '''
    
    _Mapper_ = None
    _company_id_ = -1    

    def __init__(self):
        self.uuid =''
        self.modify_time ='1999-09-09'
        self.order_count =0
        self.order_amount =0
        self.total_customer =0
        self.max_amount =0
        self.min_amount =0
        self.free_amount=0
        self.discount_amount=0
        self.service_amount=0
        self.zero_amount=0
    
    @staticmethod
    def doMapping(company_id):
        '''
                    按company_id分库，每次生成对象前都要执行一次，以便map到正确的数据库上去
        '''
        if Sell_analysis._company_id_ == company_id:
            return
                
        if Sell_analysis._Mapper_ is not None:
            Sell_analysis._Mapper_.dispose()
            
        metaData = MetaData()
        sell_analysisTable = Table('sell_analysis', metaData,
                           Column('uuid', String, primary_key = True),
                           Column('modify_time', DateTime),
                           Column('order_count', Integer),
                           Column('order_amount', Integer),
                           Column('total_customer', Integer),
                           Column('max_amount', Integer),
                           Column('min_amount', Integer),
                           Column('free_amount', Integer),
                           Column('discount_amount', Integer),
                           Column('service_amount', Integer),
                           Column('zero_amount', Integer),
                           schema = "report_%s" % company_id)
                
        Sell_analysis._Mapper_ = mapper(Sell_analysis, sell_analysisTable)
        
